<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

    <script>
    //边界符以^开头以$结束
    console.log(/哈/.test('哈'));
    console.log(/二哈/.test('二哈'));
    console.log(/二哈/.test('很二哈哈'));
    
    //以^开头
    console.log(/^哈/.test('哈'));
    console.log(/^二哈/.test('二哈'));
    console.log(/^二哈/.test('很二哈哈'));
    
    //$结尾
    console.log(/^哈$/.test('哈'));
    console.log(/^二哈$/.test('二哈很傻'));
    console.log(/^二哈$/.test('很二哈哈'));
    console.log(/^二哈$/.test('二哈二哈'));
    console.log(/^二哈$/.test('二哈'));



//量词
        //*表示重复0次或者更多次
        console.log(/^哈*$/.test(''));
        console.log(/^哈*$/.test('哈'));
        console.log(/^哈*$/.test('哈哈哈'));
        //+表示重复一次或者更多次
        console.log(/^哈+$/.test(''));
        console.log(/^哈+$/.test('哈'));
        console.log(/^哈+$/.test('哈哈哈'));
        //?表示重复0次或者1次
        console.log('--------');
        console.log(/^哈?$/.test(''));
        console.log(/^哈?$/.test('哈'));
        console.log(/^哈?$/.test('哈哈哈'));

        console.log(/^哈{2}$/.test(''));
        console.log(/^哈{2}$/.test('哈'));
        console.log(/^哈{2}$/.test('哈哈'));
        console.log(/^哈{2}$/.test('哈哈哈'));

        //{n,} 是 >=n 
        console.log(/^哈{2,}$/.test(''));
        console.log(/^哈{2,}$/.test('哈'));
        console.log(/^哈{2,}$/.test('哈哈'));
        console.log(/^哈{2,}$/.test('哈哈哈'));

        //{n,m} 是次数 >=n <=m 注意逗号左右不能有空格
        console.log(/^哈{2,4}$/.test(''));
        console.log(/^哈{2,4}$/.test('哈'));
        console.log(/^哈{2,4}$/.test('哈哈'));
        console.log(/^哈{2,4}$/.test('哈哈哈'));
        console.log(/^哈{2,4}$/.test('哈哈哈哈'));
        console.log(/^哈{2,4}$/.test('哈哈哈哈哈'));
    </script>
</body>
</html>